﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TechTalk.SpecFlow;
using YasharEl.Infrastructure.ProcessEngine.ServiceModel;
using YasharEl.Infrastructure.ServiceModel;

namespace YasharEl.Infrastructure.AllModules.AcceptanceTests.ProcessEngine.Steps
{
    [Binding]
    public class ListAllAvailableProcessDefinitionsRelatedToTestApplicationStepDefinition
    {
        #region Fields

        private RetrieveAvailableProcessDefinitionsRequest _retrieveAvailableProcessDefinitionsRequest;
        private RetrieveAvailableProcessDefinitionsResponse _retrieveAvailableProcessDefinitionsResponse;

        #endregion

        #region Given

        [Given(@"I have filled out the application id : (.*)")]
        [Scope(Tag = "ListAllAvailableProcessDefinitionsRelatedToTestApplication")]
        public void GivenIHaveFilledOutTheApplicationId(long applicationId)
        {
            _retrieveAvailableProcessDefinitionsRequest = new RetrieveAvailableProcessDefinitionsRequest();
            _retrieveAvailableProcessDefinitionsRequest.ApplicationId = applicationId;
        }

        #endregion

        #region When

        [When(@"I list available process definitions from process definitions catalog")]
        [Scope(Tag = "ListAllAvailableProcessDefinitionsRelatedToTestApplication")]
        public void WhenIListAvailableProcessDefinitionsFromProcessDefinitionsCatalog()
        {
            using (ServiceProxy<IProcessMetadataRetriever> processMetadataRetrieverProxy = new ServiceProxy<IProcessMetadataRetriever>())
            {
                _retrieveAvailableProcessDefinitionsResponse = 
                    processMetadataRetrieverProxy.Proxy.RetrieveAvailableProcessDefinitions(
                        _retrieveAvailableProcessDefinitionsRequest);
            }
        }

        #endregion

        #region Then

        [Then(@"I should receive valid response contains the returned list of process definitions")]
        [Scope(Tag = "ListAllAvailableProcessDefinitionsRelatedToTestApplication")]
        public void ThenIShouldReceiveValidResponseContainsTheReturnedListOfProcessDefinitions()
        {
            Assert.IsNotNull(_retrieveAvailableProcessDefinitionsResponse);
            Assert.IsNotNull(_retrieveAvailableProcessDefinitionsResponse.AvailableProcessDefinitions);
        }

        [Then(@"the process definitions list contains the '(.*)' process")]
        [Scope(Tag = "ListAllAvailableProcessDefinitionsRelatedToTestApplication")]
        public void ThenTheProcessDefinitionsListContainsTheProcess(string processDefinitionName)
        {
            Assert.IsNotNull(
                _retrieveAvailableProcessDefinitionsResponse.AvailableProcessDefinitions[processDefinitionName]
            );
        }


        #endregion
    }
}
